<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script> 
    function axios(options) {
        return new Promise((resolve,reject) => {
            const xhr = new XMLHttpRequest()
            xhr.open(options.method,options.url) 
            xhr.send(null)

            xhr.onreadystatechange = function() {
                if(xhr.readyState === 4) {
                    if(xhr.status === 200) {
                        console.log('请求成功')
                        resolve(JSON.parse(xhr.responseText))
                    } else {
                        console.log('请求失败')
                        reject(new Error(xhr.responseText))
                    }
                }
            }
        })
    }
    axios({
        method: 'get',
        url: 'http://localhost:3000/heroes'
    }).then(res => {
        console.log('我已成功登陆')
        console.log(res)
    })
    </script>
</body>
</html>